package cn.skyquant.quant4j.task.boot.bo;

import cn.skyquant.quant4j.task.boot.entity.Account;
import cn.skyquant.quant4j.task.boot.entity.AccountDaily;
import cn.skyquant.quant4j.task.boot.repository.AccountDailyRepository;
import cn.skyquant.quant4j.task.boot.repository.AccountRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class AccountBO {

    @Autowired
    AccountDailyRepository accountDailyRepository;

    @Autowired
    AccountRepository accountRepository;

    public void daily(){
        List<Account> accountList = accountRepository.findAll();
        accountList.stream()
                .forEach(x->dailyPerAccount(x));
    }

    public void dailyPerAccount(Account account){
        //先插入数据库
        AccountDaily accountDaily = new AccountDaily();
        accountDaily.account = account;
        accountDaily.balance = account.balance;
        accountDaily.equity = account.equity;
        accountDaily.usedMargin = account.usedMargin;
        accountDailyRepository.insert(accountDaily);
    }
}
